Why can't I add an event to each element in a collection that refers to Itself rather than the last
Posted
by user311403
on Stack Overflow
See other posts from Stack Overflow
or by user311403
Published on 2010-04-07T22:09:40Z
Indexed on
2010/04/07
22:13 UTC
Read the original article
Hit count: 346
On Window
's load, every DD
element inside Quote_App
should have an onCLick
event appended that triggers the function Lorem
, however, Lorem
returns the nodeName
and Id
of the last element in the For
statement rather than that of the element that trigged the function. I would want Lorem
to return the nodeName
and Id
of the element that triggered the function.
.js
function Lorem(Control){
/* this.Control=Control; */
this.Amet=function(){
return Control.nodeName+"\n"+Control.id;
};
};
function Event(Mode,Function,Event,Element,Capture_or_Bubble){
if(Mode.toLowerCase()!="remove"){
if(Element.addEventListener){
if(!Capture_or_Bubble){
Capture_or_Bubble=false;
}else{
if(Capture_or_Bubble.toLowerCase()!="true"){
Capture_or_Bubble=false;
}else{
Capture_or_Bubble=true;
};
};
Element.addEventListener(Event,Function,Capture_or_Bubble);
}else{
Element.attachEvent("on"+Event,Function);
};
};
};
function Controls(){
var Controls=document.getElementById("Quote_App").getElementsByTagName("dd");
for(var i=0;i
Currently you click on any DD
element Lorem
always returns the nodeName
and Id
of the last DD
element.
Lorem
should return the nodeName
and Id
of the Control
(Control[i]
) that triggered Lorem.
How do I go about making this happen?
Thank you!
© Stack Overflow or respective owner